<?php
/**
 * Created by PhpStorm.
 * User: DaibiDaddy
 * Date: 2016/6/3
 * Time: 14:59
 */

namespace Model\CourseCategoryBundle\Setting;

use Model\CourseCategoryBundle\Model\CourseCategoryModel;

class CourseCategorySetting{

    public $catType = "level";//Options:level snake
    public $entityCnName = "课程分类";
    public $table = "CourseCategory";
    public $editKeys = array("orders","link");
    public $perPage = 10;

    /*自动获取的配置项*/
    public $entity;
    public $bundleName;
    public $entityName;
    public $SettingPath;
    public $entityPath;
    public $modelPath;
    public $doctrine;

    public function __construct($doctrine)
    {
        $this->bundleName = str_replace("\\","",str_replace("Setting","",__NAMESPACE__));
        $this->entityName = str_replace("\\","",str_replace("Setting","",str_replace(__NAMESPACE__,"",__CLASS__)));
        $this->SettingPath = __CLASS__;
        $this->entityPath = str_replace($this->entityName."Entity",$this->entityName,str_replace("Setting","Entity",__CLASS__));
        $this->entity = new $this->entityPath();
        $this->modelPath = str_replace("Setting","Model",__CLASS__);
        $this->doctrine = $doctrine;
    }

    public function listConfig()
    {
        $default = array();
        $default["CourseCategory"]["select"] = array("id","name","pic","link","orders","parent","level");
        $default["CourseCategory"]["search"] = array("name");
        $default["CourseCategory"]["condition"] = array("parent");
        $default["CourseCategory"]["orderBy"] = array();

        $join = array();

        return array(
            "default"   => $default,
            "joins"     => $join,
        );
    }

    public function formConfig()
    {
        $model = new CourseCategoryModel($this->doctrine);
        $categories = $model->getAllCourseCategoryTree();
        $parents[0] = "根目录";
        foreach ($categories as $c) {
            $parents[$c["id"]] = $c["name"];
        }
        $options["parent"]["other"] = array(
            "choices"   => $parents,
        );
        $config["parent"] = array(
            "label"     =>"父级ID",
            "showType"  =>"select",
            "dataType"  =>"",
            "option"    => $options["parent"]
        );

        $config["name"] = array(
            "label"     =>"按钮名称",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );

        $config["orders"] = array(
            "label"     =>"排序",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    =>  array()
        );

        $config["pic"] = array(
            "label"     =>"图标",
            "showType"  =>"pic",
            "dataType"  =>"",
            "option"    => array()
        );

        $config["link"] = array(
            "label"     =>"链接",
            "showType"  =>"text",
            "dataType"  =>"",
            "option"    => array()
        );
        return $config;
    }
}